from contextlib import asynccontextmanager

from fastapi import Depends, FastAPI

from router import v1
from service.http import client

from .auth import get_current_username
from .init_app import init_middleware
from .scheduler import scheduler


@asynccontextmanager
async def lifespan(app: FastAPI):
	scheduler.start()
	yield
	scheduler.shutdown()
	await client.aclose()


def create_app():
	app = FastAPI(title="Api", version="1.0.0", lifespan=lifespan)
	app.include_router(v1, prefix="/api", dependencies=[Depends(get_current_username)])
	init_middleware(app)
	return app
